package com.javandad.app.server.mail.entity;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataSource;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;

import com.javandad.app.shared.entity.Mailable;

public abstract class JMail extends MimeMessage {
	

	public JMail(Session session) {
		super(session);
	}
	
	public void setSession(Session session){
		this.session = session;
	}
	
	protected abstract void adapt(Mailable a);
	
	 static class HTMLDataSource implements DataSource {
	        private String html;
	 
	        public HTMLDataSource(String htmlString) {
	            html = htmlString;
	        }
	 
	        // Return html string in an InputStream.
	        // A new stream must be returned each time.
	        public InputStream getInputStream() throws IOException {
	            if (html == null) throw new IOException("Null HTML");
	            return new ByteArrayInputStream(html.getBytes());
	        }
	 
	        public OutputStream getOutputStream() throws IOException {
	            throw new IOException("This DataHandler cannot write HTML");
	        }
	 
	        public String getContentType() {
	            return "text/html";
	        }
	 
	        public String getName() {
	            return "JAF text/html dataSource to send e-mail only";
	        }
	    }

}
